package com.cz;
import java.io.UnsupportedEncodingException;
import com.cz.common.utils.HCNetSDK;
import com.sun.jna.Pointer;
/**
 * 
 */

public class Test1 {

	static HCNetSDK hCNetSDK = HCNetSDK.INSTANCE;
	static int lUserID = -1;//用户句柄
	static int m_lSetCardCfgHandle = -1; //下发卡长连接句柄
	static int dwState = -1; //下发卡数据状态	

	/**
	 * @param args
	 * @throws UnsupportedEncodingException 
	 * @throws InterruptedException 
	 */
	public static void main(String[] args) throws UnsupportedEncodingException, InterruptedException  {
		Test1 test = new Test1();
		hCNetSDK.NET_DVR_Init();
		test.Login();				//登陆
		test.GetPDCResult();
	}

	public void Login()
	{	
		HCNetSDK.NET_DVR_DEVICEINFO_V30 m_strDeviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V30();
		lUserID = hCNetSDK.NET_DVR_Login_V30("192.168.3.104",
                (short) 8000, "admin", "YXFWQ123", m_strDeviceInfo);
		if (lUserID == -1)
		{
			System.out.println("登录失败，错误码为"+hCNetSDK.NET_DVR_GetLastError());
			return;
		} 
		else
		{
			System.out.println("登录成功！");
		}
	}
	
	
	public void GetPDCResult(){
		 	HCNetSDK.NET_DVR_PDC_QUERY_COND m_struPdcResultCond = new HCNetSDK.NET_DVR_PDC_QUERY_COND();
		 	m_struPdcResultCond.read();
			m_struPdcResultCond.dwSize = m_struPdcResultCond.size();
			m_struPdcResultCond.dwChannel = 1;
			m_struPdcResultCond.struStartTime.wYear = 2020;
			m_struPdcResultCond.struStartTime.byMonth = 4;
			m_struPdcResultCond.struStartTime.byDay = 26;
			m_struPdcResultCond.struStartTime.byHour = 0;
			m_struPdcResultCond.struStartTime.byMinute = 0;
			m_struPdcResultCond.struStartTime.bySecond = 0;
			m_struPdcResultCond.struEndTime.wYear = 2020;
			m_struPdcResultCond.struEndTime.byMonth = 4;
			m_struPdcResultCond.struEndTime.byDay = 26;
			m_struPdcResultCond.struEndTime.byHour = 23;
			m_struPdcResultCond.struEndTime.byMinute = 59;
			m_struPdcResultCond.struEndTime.bySecond = 59;                         
			m_struPdcResultCond.byReportType = 1;		
			m_struPdcResultCond.write();
			Pointer lpInBuffer = m_struPdcResultCond.getPointer();
			int lHandle = hCNetSDK.NET_DVR_StartRemoteConfig(lUserID,HCNetSDK.NET_DVR_GET_PDC_RESULT, lpInBuffer,
					m_struPdcResultCond.size(), null, null);
			
			if (lHandle < 0) {
				System.out.println("建立NET_DVR_GET_PDC_RESULT长连接失败，错误号：" + hCNetSDK.NET_DVR_GetLastError());
				return;
			}
			else{
				System.out.println("建立NET_DVR_GET_PDC_RESULT长连接成功");
						
			}
			
			HCNetSDK.NET_DVR_PDC_RESULT m_struPdcResult = new HCNetSDK.NET_DVR_PDC_RESULT();
			m_struPdcResult.write();
			Pointer pPdcResult = m_struPdcResult.getPointer();
			
			int iRetSult = 0;
			while (true) {
				iRetSult = hCNetSDK.NET_DVR_GetNextRemoteConfig(lHandle, pPdcResult, m_struPdcResult.size());
				
				if (iRetSult == 1000) {
					//System.out.println("hCNetSDK.NET_DVR_GetLastError():"+hCNetSDK.NET_DVR_GetLastError());
					//System.out.println("NET_DVR_GetNextRemoteConfig 状态  ：" + iRetSult);
					m_struPdcResult.read();
					System.out.println("-------开始时间:" + m_struPdcResult.struStartTime.wYear + "-"+ m_struPdcResult.struStartTime.byMonth
							+"-"+m_struPdcResult.struStartTime.byDay+"-" + m_struPdcResult.struStartTime.byHour+"-"+m_struPdcResult.struStartTime.byMinute
							+"-"+m_struPdcResult.struStartTime.bySecond+",结束时间:" + m_struPdcResult.struEndTime.wYear + "-"+ m_struPdcResult.struEndTime.byMonth
							+"-"+m_struPdcResult.struEndTime.byDay+"-" + m_struPdcResult.struEndTime.byHour+"-"+m_struPdcResult.struEndTime.byMinute
							+"-"+m_struPdcResult.struEndTime.bySecond + "-------");
                    System.out.println("进入人数:"+m_struPdcResult.dwEnterNum + ",离开人数:"+m_struPdcResult.dwLeaveNum);

                                            
				} else if (iRetSult == 1001) {
					//System.out.println("hCNetSDK.NET_DVR_GetLastError():"+hCNetSDK.NET_DVR_GetLastError());
					//System.out.println("NET_DVR_GetNextRemoteConfig 状态  ：" + iRetSult);
				} else if (iRetSult == 1002 || iRetSult == 1003) {
					//System.out.println("hCNetSDK.NET_DVR_GetLastError():"+hCNetSDK.NET_DVR_GetLastError());
					//System.out.println("NET_DVR_GetNextRemoteConfig 状态  ：" + iRetSult);
					
					hCNetSDK.NET_DVR_StopRemoteConfig(lHandle);
					break;
				} 
				
			}
		}
		
	

	
	
	
	 
}//Test1  Class结束
